/*******************************************************************************
 *
 * Copyright (c) 2008-2011 ayound@gmail.com, guwei8576431@gmail.com
 * This program and the accompanying materials
 * are made available under the terms of the GNU GENERAL PUBLIC LICENSE
 * which accompanies this distribution, and is available at
 * http://dev.perl.org/licenses/gpl1.html
 * All rights reserved.
 *
 * Created on 2009-10-12
 *******************************************************************************/

package org.cgtw.scriptprofile.server.model;

import java.util.HashMap;
import java.util.Map;

/**
 * store all profile data
 */
public class ProfileData {
	/**
	 * store all profileItems
	 */
	private static Map<Integer, ProfileItem> items;

	/**
	 * store all transfer relations of js functions
	 */
	private static Map<Integer, Integer[]> relations;

	/**
	 * store all root nodes of transfer stacks
	 */
	private static Integer []rootIndex;

	/**
	 * use to update the profile table view dynamically
	 * @param key
	 * @param value
	 */
	public static void addProfileItem(Integer key, ProfileItem value){
		if(items == null){
			items = new HashMap<Integer, ProfileItem>();
		}
		items.put(key, value);
	}

	/**
	 * use to update the profile stack view dynamically
	 * @param key
	 * @param value
	 */
	public static void setRelation(Integer key, Integer value[]){
		if(relations == null){
			relations = new HashMap<Integer, Integer[]>();
		}
		relations.put(key, value);
	}

	/**
	 * @return Returns the items.
	 */
	public static Map<Integer, ProfileItem> getItems() {
		return items;
	}

	/**
	 * @return Returns the relations.
	 */
	public static Map<Integer, Integer[]> getRelations() {
		return relations;
	}

	/**
	 * @return Returns the rootIndex.
	 */
	public static Integer[] getRootIndex() {
		return rootIndex;
	}

	/**
	 * @param rootIndex The rootIndex to set.
	 */
	public static void setRootIndex(Integer[] newrootIndex) {
		rootIndex = newrootIndex;
	}
	
	/**
	 * clear the data
	 */
	public static void clear(){
		items = null;
		relations = null;
		rootIndex = null;
	}
}
